package com.bvgol.quartzDemo.config;

import com.bvgol.quartzDemo.job.HelloJob;
import com.bvgol.quartzDemo.job.HelloJob2;
import org.quartz.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

import static org.quartz.SimpleScheduleBuilder.simpleSchedule;

@Component
public class HelloJobDetailConfig2 {

    @Autowired
    private Scheduler scheduler;

    @PostConstruct
    protected void InitHelloJob() throws Exception {
        JobDetail jobDetail = JobBuilder.newJob(HelloJob2.class)
                .withIdentity("helloJob2")
//                .storeDurably()
                .usingJobData("data2", "保密信息2")
                .build();
        Trigger trigger = TriggerBuilder.newTrigger()
                .withIdentity("helloTrigger2")
                .forJob("helloJob2")
                .withSchedule(simpleSchedule()
                        .withIntervalInSeconds(3)
                        .repeatForever())
                .build();
        scheduler.scheduleJob(jobDetail,trigger);
        //推荐这种写法`

    }
}
